Either

sealed class Either<out L, out R>

Disjoint union. The instance might be either Left or Right.

This type is based on scala.Either.

Parameters

L

Type of Left

R

Type of Right

Functions

all
Link copied to clipboard
common
inline fun all(predicate: (R) -> Boolean): Boolean
Returns the result of applying the predicate to the value if this is Right or true if this is Left.
any
Link copied to clipboard
common
inline fun any(predicate: (R) -> Boolean): Boolean
Returns the result of applying the predicate to the value if this is Right or false if this is Left.
contains
Link copied to clipboard
common
abstract operator fun contains(element: Any): Boolean
Returns true if the element is equal to the value of this Either, or false otherwise.
filter
Link copied to clipboard
common
inline fun filter(predicate: (R) -> Boolean): Either<L, R>?
Returns the same Right if the predicate is satisfied for the value.
filterIsInstance
Link copied to clipboard
common
inline fun <T> filterIsInstance(): Either<L, T>?
Returns the same Right casted to type T if it is T.
filterIsInstanceToOption
Link copied to clipboard
common
inline fun <T> filterIsInstanceToOption(): Option<Either<L, T>>
Returns Some containing the same Right casted to type T if it is T.
filterNot
Link copied to clipboard
common
inline fun filterNot(predicate: (R) -> Boolean): Either<L, R>?
Returns the same Right if the predicate is not satisfied for the value.
filterNotToOption
Link copied to clipboard
common
inline fun filterNotToOption(predicate: (R) -> Boolean): Option<Either<L, R>>
Returns Some containing the same Right if the predicate is not satisfied for the value.
filterToOption
Link copied to clipboard
common
inline fun filterToOption(predicate: (R) -> Boolean): Option<Either<L, R>>
Returns Some containing the same Right if the predicate is satisfied for the value.
fold
Link copied to clipboard
common
inline fun <T> fold(leftTransform: (L) -> T, rightTransform: (R) -> T): T
Transforms Left with leftTransform or Right with rightTransform.
forEach
Link copied to clipboard
common
inline fun forEach(action: (R) -> Unit)
Runs action if this is a Right.
get
Link copied to clipboard
common
fun get(): R
Gets value of this Right.
getOrNull
Link copied to clipboard
common
fun getOrNull(): R?
Gets value of this Right or null if this is Left.
map
Link copied to clipboard
common
inline fun <T> map(transform: (R) -> T): Either<L, T>
Maps value of this Right using transform.
none
Link copied to clipboard
common
inline fun none(predicate: (R) -> Boolean): Boolean
Returns false if the predicate is met by the value if this is Right or true otherwise.
swap
Link copied to clipboard
common
abstract fun swap(): Either<R, L>
Swaps Left to Right and Right to Left.
toOption
Link copied to clipboard
common
fun toOption(): Option<R>
Returns a Some containing the Right value if it exists, or a None if this is a Left.

Properties

isLeft
Link copied to clipboard
common
abstract val isLeft: Boolean
Returns true if this is a Left or false if this is Right.
isRight
Link copied to clipboard
common
abstract val isRight: Boolean
Returns true if this is a Right or false if this is Left.
left
Link copied to clipboard
common
val left: LeftProjection<L, R>
Projects Either as Left.
right
Link copied to clipboard
common
val right: RightProjection<L, R>
Projects Either as Right.

Inheritors

Left
Link copied to clipboard
Right
Link copied to clipboard

Extensions

filterNotNull
Link copied to clipboard
common
fun <L, R> Either<L, R?>.filterNotNull(): Either<L, R>?
Returns the same Right if its value is not null.
filterNotNullToOption
Link copied to clipboard
common
fun <L, R> Either<L, R?>.filterNotNullToOption(): Option<Either<L, R>>
Returns Some containing the same Right if its value is not null.
filterOrElse
Link copied to clipboard
common
inline fun <L, R> Either<L, R>.filterOrElse(predicate: (R) -> Boolean, zero: () -> L): Either<L, R>?
Returns the same Right if the predicate is satisfied for the value, Left(zero) if the predicate is not satisfied for the value, or the same Left if this is Left.
flatMap
Link copied to clipboard
common
inline fun <L, R, T> Either<L, R>.flatMap(transform: (R) -> Either<L, T>): Either<L, T>
Maps value of this Right to a new Either using transform.
getOrElse
Link copied to clipboard
common
inline fun <L, R> Either<L, R>.getOrElse(default: () -> R): R
Gets value of this Right or default value if this is Left.
joinLeft
Link copied to clipboard
common
fun <L, R> Either<Either<L, R>, R>.joinLeft(): Either<L, R>
Returns this if this is Right.
joinRight
Link copied to clipboard
common
fun <L, R> Either<L, Either<L, R>>.joinRight(): Either<L, R>
Returns this if this is Left.
merge
Link copied to clipboard
common
fun <T> Either<T, T>.merge(): T
Merges Left and Right of the same type to a single value.